//
//  YHYButtonTabBar.m
//  LANGirl
//
//  Created by 杨泓晔 on 16/3/16.
//  Copyright © 2016年 杨泓晔. All rights reserved.
//

#import "YHYButtonTabBar.h"

@interface YHYButtonTabBar ()
@property (nonatomic,retain)UIButton *shoucangButton;
@property (nonatomic,retain)UIImageView *xinImageView;
@property (nonatomic,assign)BOOL isSelrct;
@property (nonatomic,retain)UIButton *gongTongButton;
@property (nonatomic, strong) UIView *shouCangView;
@property (nonatomic, strong) UIView *goutongView;
@property (nonatomic, strong) UIButton *centerBtn;
@property (nonatomic, strong) UILabel *shouangL;
@property (nonatomic, strong) UILabel *jiaL;

@property (nonatomic,retain)UIView *linV;

@end

@implementation YHYButtonTabBar
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self tabBarButton];
        
    }
    return self;
}

    
- (void)tabBarButton{
    
    self.isSelrct = YES;
    //左边
    self.shouCangView = [[UIView alloc]init];
    
    self.shouCangView.userInteractionEnabled = YES;
    
    self.shouCangView.backgroundColor = [UIColor whiteColor];
    
    [self addSubview:_shouCangView];

    [self.shouCangView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self).offset(0);
        make.left.equalTo(self);
        make.width.mas_equalTo(self.frame.size.width/2);
        make.height.mas_equalTo(50 *AUTO_HEIGHT);
        
    }];
    
    //收藏
    self.shoucangButton = [UIButton buttonWithType:UIButtonTypeCustom];
    //裁掉边框
    self.shoucangButton.layer.masksToBounds = YES;
    //设置半径
    self.shoucangButton.layer.cornerRadius = 5;
    self.shoucangButton.backgroundColor = CHENGS;
    [self.shoucangButton addTarget:self action:@selector(centerAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.shouCangView addSubview:self.shoucangButton];
    [self.shoucangButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(self.shouCangView);
        
        make.left.equalTo(self.shouCangView).offset(30.00*AUTO_WIDTH/2);
        
        make.right.mas_equalTo(-29 / 2 * AUTO_WIDTH);
        
        make.height.mas_equalTo(70*AUTO_HEIGHT/2);
        
    }];

    
    self.xinImageView = [UIImageView new];
    //实心心
    self.xinImageView.image = [UIImage imageNamed:@"heart"];    [self.shoucangButton addSubview:self.xinImageView];
    self.xinImageView.contentMode = UIViewContentModeScaleAspectFill;
    [self.xinImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(self.shoucangButton);
        make.centerX.equalTo(self.shoucangButton).offset(-60.00*AUTO_WIDTH/2);
        make.size.mas_equalTo(CGSizeMake(27 * AUTO_HEIGHT, 27*AUTO_WIDTH));
        
    }];
    
    
     self.shouangL= [UILabel new];
    [self.shoucangButton addSubview:self.shouangL];
    [self.shouangL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.xinImageView.mas_right).offset(18 * AUTO_WIDTH);
        make.centerY.mas_equalTo(self.xinImageView);
        make.height.mas_equalTo(self.xinImageView);
    }];
    self.shouangL.text = @"收藏";
    self.shouangL.textColor = [UIColor whiteColor];
    self.shouangL.font = [UIFont fontWithName:ZIXING size:TEXTCONTENTFONT * AUTO_WIDTH];
    
    
     self.jiaL= [UILabel new];
    [self.shoucangButton addSubview:self.jiaL];
    [self.jiaL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(self.xinImageView.mas_right).offset(1 * AUTO_WIDTH);
        make.height.mas_equalTo(self.shouangL);
    }];
    self.jiaL.text = @"+";
    self.jiaL.alpha = 0.9;
    self.jiaL.textColor = [UIColor whiteColor];
    self.jiaL.font = [UIFont fontWithName:SHUZI size:26.00 * AUTO_WIDTH];
    

    self.goutongView = [UIView new];
    self.goutongView.userInteractionEnabled = YES;
    self.goutongView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_goutongView];
    [self.goutongView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom);
        
        make.right.mas_equalTo(@0);
        
        make.size.mas_equalTo(CGSizeMake(self.frame.size.width/2, 50 *AUTO_HEIGHT));
        
    }];
    self.goutongView.backgroundColor = [UIColor whiteColor];
    

    
    //沟通
    self.gongTongButton = [UIButton new];
    //裁掉边框
    self.gongTongButton.layer.masksToBounds = YES;
    //设置半径
    self.gongTongButton.layer.cornerRadius = 5;
    self.gongTongButton.backgroundColor = GOUTONG;
    
    [self.gongTongButton addTarget:self action:@selector(centerAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.goutongView addSubview:self.gongTongButton];
    
    [self.gongTongButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.goutongView);
        make.left.mas_equalTo(30/2 * AUTO_WIDTH);
        make.right.mas_equalTo(-12 * AUTO_WIDTH);
        make.height.mas_equalTo(70/2*AUTO_HEIGHT);
    }];
    
    
    self.xinImageView2 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"goutong"]];
    //  self.xinImageView2.backgroundColor = [UIColor redColor];
    [self.gongTongButton addSubview:self.xinImageView2];
    [self.xinImageView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(self.shoucangButton);
        make.centerX.mas_equalTo(-70.00*AUTO_WIDTH/2);
        make.size.mas_equalTo(CGSizeMake(25 * AUTO_HEIGHT, 25*AUTO_WIDTH));
        
    }];

    
   self.gouTongL = [UILabel new];
    [self.gongTongButton addSubview:self.gouTongL];
    [self.gouTongL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.xinImageView2.mas_right).offset(4 * AUTO_WIDTH);
        make.centerY.mas_equalTo(self.xinImageView2);
        make.height.mas_equalTo(self.xinImageView2);
    }];
    self.gouTongL.text = @"";
    self.gouTongL.textColor = [UIColor whiteColor];
    self.gouTongL.font = [UIFont fontWithName:ZIXING size:TEXTCONTENTFONT * TEXTWEIGHT];
    
    //阴影
    UIImageView *shadowImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"purse_shadow"]];
    [self addSubview:shadowImage];
    [shadowImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.mas_equalTo(@0);
        make.bottom.equalTo(self.mas_top);
        make.height.mas_equalTo(@15);
    }];
    
}

- (void)changeViewToTypeShopper {
    
    [self.shouCangView mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(CGSizeMake(self.frame.size.width/2 - 19 * AUTO_WIDTH, 50 *AUTO_HEIGHT));
    }];
    [self.goutongView mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(CGSizeMake(self.frame.size.width/2 - 19 * AUTO_WIDTH, 50 *AUTO_HEIGHT));
    }];
    
    [self.centerBtn addTarget:self action:@selector(centerAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (UIButton *)centerBtn {
    
    if (!_centerBtn) {
        
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = [UIColor whiteColor];
        [self addSubview:view];
        view.layer.cornerRadius = 25 * AUTO_WIDTH;
        view.layer.masksToBounds = YES;
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.centerX.mas_equalTo(@0);
            make.bottom.mas_offset(@(-15 * AUTO_WIDTH));
            make.size.mas_equalTo(CGSizeMake(25 * 2 * AUTO_WIDTH, 25 * 2 * AUTO_WIDTH));
        }];
        
        _centerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_centerBtn setBackgroundImage:[UIImage imageNamed:@"find_center"] forState:UIControlStateNormal];
        [view addSubview:_centerBtn];
        [_centerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.center.mas_equalTo(@0);
            make.size.mas_equalTo(CGSizeMake(19 * 2 * AUTO_WIDTH, 19 * 2 * AUTO_WIDTH));
        }];
    }
    
    return _centerBtn;
}

- (void)centerAction:(UIButton *)btn {
    
    if ([btn isEqual:self.shoucangButton]) {
        [self.delegate findButtonClickWith:FINDBUTTONCLICKCOLLECT];
        
        self.isSelrct = !self.isSelrct;
        
        if (self.isSelrct) {
            self.xinImageView.image = [UIImage imageNamed:@"heart"];
            self.jiaL.alpha=1;
            self.shouangL.text=@"收藏";
        } else{
            self.xinImageView.image = [UIImage imageNamed:@"heartShi"];
            self.jiaL.alpha=0;
            self.shouangL.text=@"已收藏";
        }
    } else if ([btn isEqual:self.gongTongButton]) {
        [self.delegate findButtonClickWith:FINDBUTTONCLICKTALK];
        
        
    } else {
        [self.delegate findButtonClickWith:FINDBUTTONCLICKCENTER];
    
    }
}

- (void)shouchangButton:(UIButton *)leftBtu{
    NSLog(@"收藏呢");
    
}

- (void)gouTongButton:(UIButton *)rightButton{
    
    [self.delegate YHYgongTongTabBar];
   
}

@end
